const router = require('koa-router')();
const rankingPartitions = require('../data/rankingPartitions')
const {
    fetchRankingById
} = require('../api')
// 向 api 服务 添加 排行榜路由模块
// 排行榜菜单
router.get('/partitions', (ctx, next) => {
    const resDate = {
        code: "0",
        message: "0",
        data:rankingPartitions
    }
    ctx.body = resDate;
})

// /ranking/1 params  query ?
router.get('/:rId', async (ctx, next) => {
    const { rId } = ctx.params;
    // console.log(rId);
    try {
        // 分层 api | controller
        const data = await fetchRankingById(rId)
        ctx.body = data;
    } catch (e) {
        next(e)
    }
    // ctx.body = rId;
})

module.exports = router.routes();